﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SocialFront.Providers.Document;
using SocialFront.Providers.Image;
using umbraco.cms.businesslogic.relation;

namespace SocialFront.Web.usercontrols.Gallery
{
    public partial class MemberImageList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Relation[] relations = Relation.GetRelations(DocumentProvider.Provider.GetCurrentPage(),
                                                         RelationType.GetByAlias("relateMemberToGalleryDocType"));

            List<Entities.Image> images = ImageProvider.Provider.GetImagesByMember(relations[0].Parent.Id);
            images = images.OrderByDescending(image => image.CreatedDate).ToList();
            lvImages.DataSource = images;
            lvImages.DataBind();
        }

        protected void lvImage_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            this.ItemDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            lvImages.DataBind();
        }
    }
}